package com.tfjybj.itoo.teach.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.teach.entity.TrainingTeachClassEntity;
import com.tfjybj.itoo.teach.model.ArrangeCourseModel;
import com.tfjybj.itoo.teach.model.TrainingTeachClassModel;
import com.tfjybj.itoo.teach.provider.service.TrainingTeachClassService;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * TrainingTeachClassController
 * trainingTeachClass表
 *
 * @author 田成荣
 * @version 2.0.0
 * @since 2.0.0 2018-11-08 19:34:10
 */
@Api(tags = {"trainingTeachClass表接口"})
@RequestMapping(value = "/trainingTeachClass")
@RestController
public class TrainingTeachClassController {

    @Resource
    private TrainingTeachClassService trainingTeachClassService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model TrainingTeachClassModel
     * @return 添加的结果
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody TrainingTeachClassModel model) {
		if (StringUtils.isEmpty(model.getTrainingProgramsId())){
            return ItooResult.build(ItooResult.FAIL, "trainingProgramsId为空");
        }
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
        TrainingTeachClassEntity trainingTeachClassEntity = new TrainingTeachClassEntity();
        BeanUtils.copyProperties(model, trainingTeachClassEntity);
        trainingTeachClassService.save(trainingTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        trainingTeachClassService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        trainingTeachClassService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model TrainingTeachClassModel
     * @return 修改后的结果
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id修改trainingTeachClass")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody TrainingTeachClassModel model) {
		if (StringUtils.isEmpty(model.getTrainingProgramsId())){
            return ItooResult.build(ItooResult.FAIL, "trainingProgramsId为空");
        }
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
        TrainingTeachClassEntity trainingTeachClassEntity = new TrainingTeachClassEntity();
        BeanUtils.copyProperties(model, trainingTeachClassEntity);
        trainingTeachClassService.updateById(trainingTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找TrainingTeachClass
     *
     * @param id 主键id
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        TrainingTeachClassEntity trainingTeachClassEntity = trainingTeachClassService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingTeachClassEntity);
    }

    /**
     * 分页查询所有TrainingTeachClass
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "分页查询所有TrainingTeachClass")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo,
                                   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<TrainingTeachClassEntity> trainingTeachClasss = trainingTeachClassService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingTeachClasss);
    }
	
	/**
     * 根据培养计划id模糊查询trainingTeachClass
     *
     * @param trainingProgramsId  培养计划id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的trainingTeachClass
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据培养计划id模糊查询trainingTeachClass", notes = "分页根据培养计划id模糊查询trainingTeachClass")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", dataType = "int", required = true, example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "记录数", dataType = "int", required = true, example = "10")
    })
    @GetMapping(value = "queryTrainingTeachClassByLikeTrainingProgramsId/{pageNo}/{pageSize}")
    public ItooResult queryTrainingTeachClassByLikeTrainingProgramsId(@RequestParam(required = false, defaultValue = "") String trainingProgramsId,
                                                                      @PathVariable Integer pageNo, @PathVariable Integer pageSize) {
        PageInfo<TrainingTeachClassEntity> trainingTeachClassList = trainingTeachClassService.queryByLikeTrainingProgramsId(trainingProgramsId, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingTeachClassList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */


    /**
     * 排课接口--添加上课班+上课班与行政班关系+上课班与培养计划关系
     *
     * @param arrangeCourseModel  行政班
     * @return  trainingTeachClassid 上课班id
     * @author 胡泽宽
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "排课接口--添加上课班+上课班与行政班关系+上课班与培养计划关系", notes = "排课接口--添加上课班+上课班与行政班关系+上课班与培养计划关系")
    @PostMapping(value = {"/insertTeachClass"})
    public ItooResult insertTeachClass(@RequestBody ArrangeCourseModel arrangeCourseModel) {
        String trainingTeachClassid = trainingTeachClassService.insertTeachClass(arrangeCourseModel);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", trainingTeachClassid);
    }

    /**
     * 删除
     *
     * @param id 上课班id
     * @return ItooResult 是否删除成功
     * @author 胡泽宽
     * @since 2.0.0 2018年11月22日 09:13:17
     */
    @ApiOperation(value = "根据上课班id删除整个上课班")
    @DeleteMapping(value = {"/deleteTeachClass/{id}"})
    public ItooResult deleteTeachClass(@ApiParam(value = "上课班id", required = true) @PathVariable String id) {
        int resutlt= trainingTeachClassService.deleteTeachClass(id);
        if(resutlt>0){
            return ItooResult.build(ItooResult.SUCCESS, "删除成功");
        }
        return ItooResult.build(ItooResult.FAIL, "删除失败");
    }

}    
